package GUILag;
/**
 * Bruges til at starte de forskellige moduler op som er i progammet.
 * @author DM75 Gruppe 3
 * @version 2011-12-22
 */
public class MainGUI extends javax.swing.JFrame {
    private String userLevel;
    private LoginGUI loginGUI;
    /** Creates new form MainGUI */
    public MainGUI(String userLevel, LoginGUI loginGUI) {
        initComponents();
        this.userLevel = userLevel;
        this.loginGUI = loginGUI;
        loginUserLabel.setText("Logget ind: " + userLevel);
        checkUserLevel();
    }
    
    public MainGUI()
    {
        initComponents();
    }
    
    private void checkUserLevel()
    {
        if(!userLevel.equals("Administrator"))
        {
            administrationButton.setEnabled(false);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        orderButton = new javax.swing.JButton();
        laneErrorButton = new javax.swing.JButton();
        workingplanButton = new javax.swing.JButton();
        lockerButton = new javax.swing.JButton();
        administrationButton = new javax.swing.JButton();
        logOffButton = new javax.swing.JButton();
        loginUserLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Løvvang Bowling Center");
        setResizable(false);

        mainPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Hovedmenu"));

        orderButton.setText("Arrangement");
        orderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                orderButtonActionPerformed(evt);
            }
        });

        laneErrorButton.setText("Banefejl");
        laneErrorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                laneErrorButtonActionPerformed(evt);
            }
        });

        workingplanButton.setText("Vagtplan");
        workingplanButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                workingplanButtonActionPerformed(evt);
            }
        });

        lockerButton.setText("Skabsudlejning");
        lockerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lockerButtonActionPerformed(evt);
            }
        });

        administrationButton.setText("Administration");
        administrationButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                administrationButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(workingplanButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(orderButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 226, Short.MAX_VALUE)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lockerButton)
                            .addComponent(laneErrorButton)))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(173, 173, 173)
                        .addComponent(administrationButton)))
                .addContainerGap())
        );

        mainPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {administrationButton, laneErrorButton, lockerButton, orderButton, workingplanButton});

        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(orderButton)
                    .addComponent(laneErrorButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(workingplanButton)
                    .addComponent(lockerButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(administrationButton)
                .addGap(16, 16, 16))
        );

        logOffButton.setText("Log af");
        logOffButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logOffButtonActionPerformed(evt);
            }
        });

        loginUserLabel.setText("Logget ind:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(339, Short.MAX_VALUE)
                .addComponent(loginUserLabel)
                .addGap(18, 18, 18)
                .addComponent(logOffButton)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(logOffButton)
                    .addComponent(loginUserLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void orderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderButtonActionPerformed
        OrderFrame orderFrame = OrderFrame.getInstance();
        orderFrame.populateComboBoxes();
        orderFrame.setVisible(true);
        orderFrame.setEnabled(true);
    }//GEN-LAST:event_orderButtonActionPerformed

    private void administrationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_administrationButtonActionPerformed
        AdmGUI admGUI = AdmGUI.getInstance();
        admGUI.setVisible(true);
    }//GEN-LAST:event_administrationButtonActionPerformed

    private void workingplanButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_workingplanButtonActionPerformed
        WorkingPlanGUI WPGUI = WorkingPlanGUI.getInstance(userLevel);
        WPGUI.setVisible(true);
    }//GEN-LAST:event_workingplanButtonActionPerformed

    private void logOffButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logOffButtonActionPerformed

        //For at være sikre på at alle frames er lukket når vi trykker på log af.
        OrderFrame orderFrame = OrderFrame.getInstance();
        orderFrame.dispose();
        
        AdmGUI admGUI = AdmGUI.getInstance();
        admGUI.dispose();
        
        WorkingPlanGUI WPGUI = WorkingPlanGUI.getInstance(userLevel);
        WPGUI.dispose();
        WPGUI.killThis();
        
        LaneErrorGUI LEPanel = LaneErrorGUI.getInstance();
        LEPanel.dispose();
        
        LockerGUI lockerGUI = LockerGUI.getInstance();
        lockerGUI.dispose();
        
        this.dispose();
        
        loginGUI.setVisible(true);
        loginGUI.userTextFFocus();
    }//GEN-LAST:event_logOffButtonActionPerformed

    private void laneErrorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_laneErrorButtonActionPerformed
        LaneErrorGUI LEPanel = LaneErrorGUI.getInstance();
        LEPanel.setVisible(true);
    }//GEN-LAST:event_laneErrorButtonActionPerformed

    private void lockerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lockerButtonActionPerformed
        LockerGUI lockerGUI = LockerGUI.getInstance();
        lockerGUI.updateTable();
        lockerGUI.setVisible(true);           
    }//GEN-LAST:event_lockerButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() 
            {   
                new MainGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton administrationButton;
    private javax.swing.JButton laneErrorButton;
    private javax.swing.JButton lockerButton;
    private javax.swing.JButton logOffButton;
    private javax.swing.JLabel loginUserLabel;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton orderButton;
    private javax.swing.JButton workingplanButton;
    // End of variables declaration//GEN-END:variables
}
